package gecp;

import gecp.edge.Detector;
import gecp.edge.Line;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.Random;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.JComponent;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileNameExtensionFilter;

/**
 * GECPMain
 *
 * @author Cosmin
 */
public class GECPMain extends javax.swing.JFrame {

    protected String _filename;
    public volatile ImagePanel _imagePanel;
    public EdgeThread edgeThread;

    class FilteredStream extends FilterOutputStream {

        public FilteredStream(OutputStream aStream) {
            super(aStream);
        }

        @Override
        public void write(byte b[]) throws IOException {
            String aString = new String(b);
            logText.append(aString);
            this.scrollToBottom();
        }

        @Override
        public void write(byte b[], int off, int len) throws IOException {
            String aString = new String(b, off, len);
            logText.append(aString);
            this.scrollToBottom();
        }

        public void scrollToBottom() {
            logText.setCaretPosition(logText.getDocument().getLength());
        }
    }

    class ImagePanel extends JComponent {

        public Detector detector;
        public BufferedImage image;

        public ImagePanel(BufferedImage image) {
            this.detector = null;
            this.image = image;
        }

        @Override
        protected void paintComponent(Graphics g) {
            g.drawImage(image, 0, 0, null);
            try {
                if (null != this.detector && null != this.detector.lines && !this.detector.lines.isEmpty()) {
                    Random random = new Random();
                    for (Line line : this.detector.lines) {
                        int rgb = random.nextInt();
                        g.setColor(new Color(rgb));
                        this.drawThickLine(g, line.from.x, line.from.y, line.to.x, line.to.y, 3, new Color(rgb));
                        //g.drawLine(line.from.x, line.from.y, line.to.x, line.to.y);
                    }
                }
            } catch (Exception ex) {
                Logger.getLogger(ImagePanel.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

        public void drawThickLine(Graphics g, int x1, int y1, int x2, int y2, int thickness, Color c) {
            // The thick line is in fact a filled polygon
            g.setColor(c);
            int dX = x2 - x1;
            int dY = y2 - y1;
            // line length
            double lineLength = Math.sqrt(dX * dX + dY * dY);

            double scale = (double) (thickness) / (2 * lineLength);

            // The x,y increments from an endpoint needed to create a rectangle...
            double ddx = -scale * (double) dY;
            double ddy = scale * (double) dX;
            ddx += (ddx > 0) ? 0.5 : -0.5;
            ddy += (ddy > 0) ? 0.5 : -0.5;
            int dx = (int) ddx;
            int dy = (int) ddy;

            // Now we can compute the corner points...
            int xPoints[] = new int[4];
            int yPoints[] = new int[4];

            xPoints[0] = x1 + dx;
            yPoints[0] = y1 + dy;
            xPoints[1] = x1 - dx;
            yPoints[1] = y1 - dy;
            xPoints[2] = x2 - dx;
            yPoints[2] = y2 - dy;
            xPoints[3] = x2 + dx;
            yPoints[3] = y2 + dy;

            g.fillPolygon(xPoints, yPoints, 4);
        }
    }

    class EdgeThread extends Thread {

        public int step;
        public double thresholder;

        public EdgeThread(int step, double thresholder) {
            this.step = step;
            this.thresholder = thresholder;
        }

        @Override
        public void run() {
            _imagePanel.detector.compute(step, thresholder);
            System.gc();
            _imagePanel.repaint();
            cancelButton.setEnabled(false);
            System.out.println("Done repaint");
            System.out.println("--------------------------------------------------");
        }
    }

    /**
     * Creates new form GECPMain
     */
    public GECPMain() {
        initComponents();
        PrintStream aPrintStream = new PrintStream(new FilteredStream(new ByteArrayOutputStream()));
        System.setOut(aPrintStream);
        System.setErr(aPrintStream);
        this._imagePanel = null;
        this._filename = null;
        this.openFile.addChoosableFileFilter(new FileNameExtensionFilter("All images", "jpg", "jpeg", "png"));
        this.openFile.addChoosableFileFilter(new FileNameExtensionFilter("JPEGs", "jpg", "jpeg"));
        this.openFile.addChoosableFileFilter(new FileNameExtensionFilter("PNGs", "png"));
        Detector.usePNG = this.usePNGCheckBox.isSelected();
        Detector.useCache = this.useCacheCheckBox.isSelected();
        this.processButton.setEnabled(false);
        this.cancelButton.setEnabled(false);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        openFile = new javax.swing.JFileChooser();
        jPanel1 = new javax.swing.JPanel();
        openButton = new javax.swing.JButton();
        stepValue = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        thresholderValue = new javax.swing.JSpinner();
        jPanel3 = new javax.swing.JPanel();
        usePNGCheckBox = new javax.swing.JCheckBox();
        useCacheCheckBox = new javax.swing.JCheckBox();
        jPanel5 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        logText = new javax.swing.JTextArea();
        jLabel4 = new javax.swing.JLabel();
        processButton = new javax.swing.JButton();
        cancelButton = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        filenameBox = new javax.swing.JTextField();
        jPanel4 = new javax.swing.JPanel();
        imageScrollPane = new javax.swing.JScrollPane();
        imageLabel = new javax.swing.JLabel();

        openFile.setAcceptAllFileFilterUsed(false);
        openFile.setApproveButtonText("Open");
        openFile.setName("Open image"); // NOI18N

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("GE by Cosmin Petrescu");

        openButton.setText("Open image");
        openButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                openButtonActionPerformed(evt);
            }
        });

        stepValue.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5" }));

        jLabel1.setText("Step");

        jLabel2.setText("Thresholder");

        usePNGCheckBox.setText("Generate output PNG for debug");
        usePNGCheckBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                usePNGCheckBoxActionPerformed(evt);
            }
        });

        useCacheCheckBox.setSelected(true);
        useCacheCheckBox.setText("Use cache for force computing (Recommanded)");
        useCacheCheckBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                useCacheCheckBoxActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanel3Layout = new org.jdesktop.layout.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(useCacheCheckBox, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 373, Short.MAX_VALUE)
                    .add(usePNGCheckBox, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .add(usePNGCheckBox)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(useCacheCheckBox)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        logText.setEditable(false);
        logText.setColumns(20);
        logText.setRows(5);
        jScrollPane2.setViewportView(logText);

        jLabel4.setText("Log");

        org.jdesktop.layout.GroupLayout jPanel5Layout = new org.jdesktop.layout.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jScrollPane2)
            .add(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel4)
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel4)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 264, Short.MAX_VALUE))
        );

        processButton.setText("Process");
        processButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                processButtonActionPerformed(evt);
            }
        });

        cancelButton.setText("Cancel");
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButtonActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(openButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(jPanel5, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jPanel1Layout.createSequentialGroup()
                                .add(jLabel1)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(stepValue, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .add(jPanel1Layout.createSequentialGroup()
                                .add(jLabel2)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(thresholderValue)))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                            .add(processButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(cancelButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .add(4, 4, 4)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .add(openButton)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                        .add(stepValue, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(jLabel1))
                    .add(processButton))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel2)
                    .add(thresholderValue, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(cancelButton))
                .add(7, 7, 7)
                .add(jPanel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel5, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        filenameBox.setEditable(false);

        org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .add(filenameBox)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .add(filenameBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        imageScrollPane.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
        imageScrollPane.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        imageScrollPane.setAutoscrolls(true);
        imageScrollPane.setViewportView(imageLabel);

        org.jdesktop.layout.GroupLayout jPanel4Layout = new org.jdesktop.layout.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .add(imageScrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 264, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .add(imageScrollPane)
                .addContainerGap())
        );

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(jPanel4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .add(layout.createSequentialGroup()
                .add(jPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void openButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openButtonActionPerformed
        int openButtonValue = this.openFile.showOpenDialog(this);
        if (openButtonValue == JFileChooser.APPROVE_OPTION) {
            this._filename = this.openFile.getSelectedFile().toString();
            this.filenameBox.setText(this._filename);
            try {
                BufferedImage image = ImageIO.read(new File(this._filename));
                if (null == this._imagePanel) {
                    this._imagePanel = new ImagePanel(image);
                    this.imageScrollPane.setViewportView(this._imagePanel);
                } else {
                    this._imagePanel.detector = null;
                    this._imagePanel.image = image;
                }
                System.gc();
                this._imagePanel.setSize(image.getWidth(), image.getHeight());
                this._imagePanel.setPreferredSize(new Dimension(image.getWidth(), image.getHeight()));
                this._imagePanel.repaint();
                System.out.println("Image loaded: " + this._filename + " with size: " + image.getWidth() + "x" + image.getHeight());
                this.processButton.setEnabled(true);
            } catch (Exception e) {
                this._filename = null;
                this.processButton.setEnabled(false);
                JOptionPane.showMessageDialog(this, "Error while loading the image. Please choose another one!", "Error", JOptionPane.ERROR_MESSAGE);
            }
        }
    }//GEN-LAST:event_openButtonActionPerformed

    private void usePNGCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_usePNGCheckBoxActionPerformed
        Detector.usePNG = this.usePNGCheckBox.isSelected();
    }//GEN-LAST:event_usePNGCheckBoxActionPerformed

    private void processButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_processButtonActionPerformed
        if (null == this._filename) {
            JOptionPane.showMessageDialog(this, "Please select an image first!", "Error", JOptionPane.ERROR_MESSAGE);
        } else {
            try {
                System.out.println("--------------------------------------------------");
                int step = Integer.parseInt(this.stepValue.getSelectedItem().toString());
                double thresholder = Double.parseDouble(this.thresholderValue.getValue().toString());
                System.out.println("Starting computation for step: " + step + " and thresholder: " + thresholder);
                this._imagePanel.detector = new Detector(this._filename);
                this.edgeThread = new EdgeThread(step, thresholder);
                this.cancelButton.setEnabled(true);
                edgeThread.start();
            } catch (Exception ex) {
                this._imagePanel = null;
                this.processButton.setEnabled(false);
                JOptionPane.showMessageDialog(this, "Error while processing the image. Please choose another one!", "Error", JOptionPane.ERROR_MESSAGE);
            }
        }
    }//GEN-LAST:event_processButtonActionPerformed

    private void useCacheCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_useCacheCheckBoxActionPerformed
        Detector.useCache = this.useCacheCheckBox.isSelected();
    }//GEN-LAST:event_useCacheCheckBoxActionPerformed

    private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
        if (this.edgeThread.isAlive()) {
            this.edgeThread.stop();
            this.processButton.setEnabled(true);
            this.cancelButton.setEnabled(false);
        }
    }//GEN-LAST:event_cancelButtonActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(GECPMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(GECPMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(GECPMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(GECPMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new GECPMain().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cancelButton;
    private javax.swing.JTextField filenameBox;
    private javax.swing.JLabel imageLabel;
    private javax.swing.JScrollPane imageScrollPane;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextArea logText;
    private javax.swing.JButton openButton;
    private javax.swing.JFileChooser openFile;
    private javax.swing.JButton processButton;
    private javax.swing.JComboBox stepValue;
    private javax.swing.JSpinner thresholderValue;
    private javax.swing.JCheckBox useCacheCheckBox;
    private javax.swing.JCheckBox usePNGCheckBox;
    // End of variables declaration//GEN-END:variables
}
